//
//  SYNavigationBar.m
//  ChatDemo-UI2.0
//
//  Created by Sylar on 16/8/18.
//  Copyright © 2016年 Sylar. All rights reserved.
//

#import "SYNavigationBar.h"
#import "PJUltraThinLine.h"
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
@class PJUltraThinLine;
@implementation SYNavigationBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = YES;
        self.clipsToBounds = NO;
        self.autoresizesSubviews = YES;
        [self setUpView];
    }
    return self;
}

- (void)setUpView
{
    _backgroundView = [[UIView alloc] initWithFrame:self.bounds];
    _backgroundView.backgroundColor = [UIColor clearColor];
    _backgroundView.clipsToBounds = NO;
    _backgroundView.autoresizesSubviews = YES;
    _backgroundView.userInteractionEnabled = YES;
    _backgroundView.autoresizingMask = ~UIViewAutoresizingNone;
    [self addSubview:_backgroundView];
    
    
//    _navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0,0, CGRectGetWidth(_backgroundView.frame), SafeAreaTopHeight)];
//    _navigationBar.userInteractionEnabled = YES;
//    _navigationBar.shadowImage = [UIImage new];
//    [_navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//    _navigationBar.backgroundColor = [UIColor clearColor];
//    if (iOS7_or_Later) {
//        _navigationBar.barTintColor = [UIColor clearColor];
//        _navigationBar.tintColor = RGBCOLOR(59, 59, 59);
//
//        [_navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:18], NSForegroundColorAttributeName: [UIColor blackColor]}];
//    }else {
////        [_navigationBar setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor blackColor], UITextAttributeFont : [UIFont systemFontOfSize:18], UITextAttributeTextShadowColor: [UIColor clearColor]}];
//    }
//
//    [_backgroundView addSubview:_navigationBar];
//
//
//    _navigationItem = [[UINavigationItem alloc] init];
//    [_navigationBar setItems:@[_navigationItem]];
//
    
    // 3、 创建标题
    self.nav_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, SCREENWIDTH, 44)];
    self.nav_titleLabel.textAlignment = NSTextAlignmentCenter;
    self.nav_titleLabel.textColor = [UIColor blackColor];
    self.nav_titleLabel.font =[UIFont boldSystemFontOfSize:18.0f];
    [_backgroundView addSubview:self.nav_titleLabel];
    
    //中间图片，为nav下拉
    self.centerImg =[[UIImageView alloc]initWithFrame:CGRectMake((SCREENWIDTH - 120)/2, SafeAreaTopHeight - 44, 120, 44)];
    self.centerImg.userInteractionEnabled = YES;
    self.centerImg.backgroundColor= [UIColor clearColor];
    self.centerImg.hidden = YES;
    [_backgroundView addSubview:self.centerImg];
   
   //中间图片，为nav下拉
   self.centerView =[[UIView alloc] initWithFrame:CGRectMake((SCREENWIDTH - 194)/2, SafeAreaTopHeight - 44, 194, 44)];
   self.centerView.userInteractionEnabled = YES;
   self.centerView.backgroundColor= [UIColor clearColor];
   self.centerView.hidden = YES;
   [_backgroundView addSubview:self.centerView];
   
    
    //4.创建返回按钮image
    self.backImg =[[UIImageView alloc]initWithFrame:CGRectMake(14, kStatusBarHeight+(44-19)/2, 11, 19)];
    self.backImg.backgroundColor =[UIColor clearColor];
    self.backImg.clipsToBounds =YES;
    self.backImg.contentMode =UIViewContentModeScaleAspectFit;
    self.backImg.image =[UIImage imageNamed:@"back"];
    [_backgroundView addSubview:self.backImg];
    
    
    // 5. 创建返回按钮
    self.backButton =[[UIButton alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight-44, 50, 44)];
    self.backButton.titleLabel.font =[UIFont systemFontOfSize:14.0];
    self.backButton.titleLabel.textAlignment =NSTextAlignmentLeft;
//    [self.backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [_backgroundView addSubview:self.backButton];
    
    
    
    //4.创建右侧按钮image
    self.rightImg =[[UIImageView alloc]initWithFrame:CGRectMake(SCREENWIDTH-40, kStatusBarHeight+(44-20)/2, 20, 20)];
    self.rightImg.backgroundColor =[UIColor clearColor];
    self.rightImg.clipsToBounds =YES;
    self.rightImg.contentMode =UIViewContentModeScaleAspectFit;
    [_backgroundView addSubview:self.rightImg];
    self.rightImg.hidden =YES;
    
    // 4. 创建导航栏右侧第一按钮
    self.rightButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREENWIDTH-70, SafeAreaTopHeight-44, 60, 44)];
    self.rightButton.backgroundColor =[UIColor clearColor];
    [self.rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.rightButton.titleLabel.font =[UIFont systemFontOfSize:14.0];
    self.rightButton.titleLabel.textAlignment =NSTextAlignmentRight;
    [self.rightButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    self.rightButton.hidden= YES;
    [_backgroundView addSubview:self.rightButton];
   
   // 4. 创建导航栏右侧第一按钮
   self.rightButton1 = [[UIButton alloc] initWithFrame:CGRectMake(SCREENWIDTH-70, SafeAreaTopHeight-44, 60, 44)];
   self.rightButton1.backgroundColor =[UIColor whiteColor];
   self.rightButton1.hidden= YES;
   [_backgroundView addSubview:self.rightButton1];
   
   // 4. 创建导航栏右侧第一按钮
   self.rightButton2 = [[UIButton alloc] initWithFrame:CGRectMake(SCREENWIDTH-70, SafeAreaTopHeight-44, 60, 44)];
   self.rightButton2.backgroundColor =[UIColor whiteColor];
   self.rightButton2.hidden= YES;
   [_backgroundView addSubview:self.rightButton2];
    
    
    _bottomLine = [[PJUltraThinLine alloc] initWithFrame:CGRectMake(0, _backgroundView.height-0.5, _backgroundView.width, 0.5)];
    _bottomLine.lineColor = [UIColor blackColor];
    _bottomLine.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    [_backgroundView addSubview:_bottomLine];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //self.bottomLine.lineColor = NavBarLightGrayColor;
    self.bottomLine.lineColor = [UIColor colorWithHexString:@"#B2B2B2"];
    //[_backgroundView bringSubviewToFront:_bottomLine];
}

- (void)setBackgroundColor:(UIColor *)color
{
    if (!color) {
        return;
    }
    _backgroundView.backgroundColor = color;
}

@end
